var maxArea = function(height) {
    let l = 0, r = height.length - 1;
    let maxArea = 0;

    while (l < r) {
        // 计算当前面积
        let area = Math.min(height[l], height[r]) * (r - l);
        maxArea = Math.max(maxArea, area);

        // 移动短板，试图找到更大的高度
        if (height[l] < height[r]) {
            l++;
        } else {
            r--;
        }
    }

    return maxArea;
};

let height=[8,7,2,1] //49
console.log(maxArea(height));